package com.ycu.jk16.mall.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ycu.jk16.mall.dao.ProductDao;
import com.ycu.jk16.mall.dao.ProductPhotoDao;
import com.ycu.jk16.mall.domain.Product;
import com.ycu.jk16.mall.domain.ProductPhoto;
import com.ycu.jk16.mall.service.ProductService;

@Service("productService")
public class ProductServiceImpl implements ProductService {

	/**
	 * 注入持久层对象
	 */
	@Autowired
	private ProductDao productDao;
	@Autowired
	private ProductPhotoDao productPhotoDao;

	public List<Product> productList(Map<String, Object> params) {
		return this.productDao.selectProductWithParam(params);
	}

	public int countProduct() {
		return this.productDao.countProduct().intValue();
	}

	public void saveProduct(Product product) {
		this.productDao.insertProduct(product);
	}

	public void saveProductPhoto(ProductPhoto photo) {
		this.productPhotoDao.insertProductPhoto(photo);
	}

	public int lastProductId(String name) {
		return this.productDao.lastProductId(name).intValue();
	}

	public void updateProduct(Product product) {
		this.productDao.updateProduct(product);
	}

	public Product selectById(Integer id) {
		return this.productDao.selectById(id);
	}

	public List<ProductPhoto> selectProductPhotoListById(Integer id) {
		return this.productPhotoDao.selectById(id);
	}

	public void deleteProductPhotoById(Integer id) {
		this.productPhotoDao.deleteProductPhotoById(id);
	}

}
